package com.yanqu.road.server.cmd.union.cross;

import com.yanqu.road.entity.player.UserBaseInfo;
import com.yanqu.road.entity.union.cross.CrossUnionMember;
import com.yanqu.road.entity.union.cross.CrossUnionNotice;
import com.yanqu.road.logic.pb.CrossUnionPb;
import com.yanqu.road.server.cmd.CrossCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.logic.MessageHelper;
import com.yanqu.road.server.manager.union.CrossUnionMgr;
import com.yanqu.road.server.manager.union.CrossUnionNoticeMgr;
import com.yanqu.road.server.manager.user.CrossUserMgr;
import com.yanqu.road.utils.YanQuMessageUtils;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.Protocol;
import com.yanqu.road.utils.string.StringUtils;

import java.util.List;

@Cmd(code = Protocol.C_UNION_NOTICE_LIST, desc = "获取公告列表")
public class CrossUnionNoticeListCmd extends CrossCommand {


	private List<CrossUnionNotice> unionNoticeList;

	@Override
	public boolean parseData(YanQuMessage packet) throws Exception {
		return true;
	}

	@Override
	public void execute(YanQuMessage packet) throws Exception {

		UserBaseInfo userBaseInfo = CrossUserMgr.getUserBaseInfo(packet.getPlayerId());
		CrossUnionMember member = CrossUnionMgr.getUnionMember(userBaseInfo.getUnionUid(), packet.getPlayerId());
		if(member != null && !StringUtils.isNullOrEmpty(member.getUnionUid())) {

			unionNoticeList = CrossUnionNoticeMgr.getUnionNoticeList(member.getUnionUid());

			MessageHelper.sendPacket(serverId, packet.getPlayerId(), YanQuMessageUtils.buildMessage(Protocol.U_UNION_NOTICE_LIST, CrossUnionPb.parseUnionNoticeListMsg(unionNoticeList)));

		}
	}

	@Override
	public void sendData() {

	}


}
